import { viteStaticCopy } from 'vite-plugin-static-copy'
import path from 'path'
import fs from 'fs'

export default function createCesiumPlugin() {
    const cesiumPath = path.resolve(__dirname, '../../node_modules/cesium/Build/Cesium')
    const targets = []

    // Only add targets that exist
    if (fs.existsSync(path.join(cesiumPath, 'Workers'))) {
        targets.push({
            src: path.join(cesiumPath, 'Workers'),
            dest: 'cesium'
        })
    }

    if (fs.existsSync(path.join(cesiumPath, 'ThirdParty'))) {
        targets.push({
            src: path.join(cesiumPath, 'ThirdParty'),
            dest: 'cesium'
        })
    }

    if (fs.existsSync(path.join(cesiumPath, 'Assets'))) {
        targets.push({
            src: path.join(cesiumPath, 'Assets'),
            dest: 'cesium'
        })
    }

    return viteStaticCopy({ targets })
}